package com.leadership.entity.course;

import javax.persistence.GenerationType;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.leadership.entity.user.User;

/**
 * 学员课程记录
 * @author haiyan_xiao
 *
 */
@Entity
@Table(name = "course_learning")
public class CourseLearning {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    
    /**
     * 学员邮箱
     */
    private String email;
    
    /**
     * 学员
     */
    @ManyToOne(fetch = FetchType.LAZY, optional = true)
    private User user;
    
    /**
     * 课程
     */
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    private LdCourse course;
    
    private Long projectId;
    
    /**
     * 创建时间
     */
    private Date createTime;
    
    /**
     * 更新时间
     */
    private Date updateTime;
    
    /**
     * 是否完成
     */
    @Column(name = "is_completed")
    private boolean completed;
    
    /**
     * 成绩
     */
    private Integer grade;
    
    public CourseLearning() {
        
    }

    public CourseLearning(String email, User user, LdCourse course, boolean completed, Integer grade) {
        this.email = email;
        this.user = user;
        this.course = course;
        this.completed = completed;
        this.grade = grade;
        this.createTime = new Date();
        this.updateTime = new Date();
    }

    public CourseLearning update(boolean completed, Integer grade) {
        this.completed = completed;
        this.grade = grade;
        this.updateTime = new Date();
        
        return this;
    }
    
    /**
     * 
     * @param course
     * @param user
     */
    public CourseLearning(LdCourse course, User user) {
        this.email = user.getEmail();
        this.user = user;
        this.course = course;
        this.createTime = new Date();
        this.updateTime = new Date();
        this.completed = false;
        this.projectId = user.getCurrentProjectId();
    }
    
    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @return the email
     */
    public String getEmail() {
        return email;
    }

    /**
     * @param email the email to set
     */
    public void setEmail(String email) {
        this.email = email;
    }

    /**
     * @return the user
     */
    public User getUser() {
        return user;
    }

    /**
     * @param user the user to set
     */
    public void setUser(User user) {
        this.user = user;
    }

    /**
     * @return the course
     */
    public LdCourse getCourse() {
        return course;
    }

    /**
     * @param course the course to set
     */
    public void setCourse(LdCourse course) {
        this.course = course;
    }

    /**
     * @return the createTime
     */
    public Date getCreateTime() {
        return createTime;
    }

    /**
     * @return the projectId
     */
    public Long getProjectId() {
        return projectId;
    }

    /**
     * @param createTime the createTime to set
     */
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    /**
     * @return the updateTime
     */
    public Date getUpdateTime() {
        return updateTime;
    }

    /**
     * @param updateTime the updateTime to set
     */
    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    /**
     * @return the completed
     */
    public boolean isCompleted() {
        return completed;
    }

    /**
     * @param completed the completed to set
     */
    public void setCompleted(boolean completed) {
        this.completed = completed;
    }

    /**
     * @return the grade
     */
    public Integer getGrade() {
        return grade;
    }

    /**
     * @param grade the grade to set
     */
    public void setGrade(Integer grade) {
        this.grade = grade;
    }

    /**
     * @param projectId the projectId to set
     */
    public void setProjectId(Long projectId) {
        this.projectId = projectId;
    }
    
}
